package com.wuming.caiwu.controller;

import com.wuming.caiwu.core.BusinessException;
import com.wuming.caiwu.core.CommonResult;
import com.wuming.caiwu.model.QsgHexiao;
import com.wuming.caiwu.model.QsgRechargeOrder;
import com.wuming.caiwu.service.QsgHexiaoService;
import com.wuming.caiwu.service.QsgRechargeOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by hanfei on 16/4/19.
 */
@Controller
@RequestMapping("/web/hexiao")
public class QsgHexiaoController extends BaseController {

    @Autowired
    private QsgHexiaoService hexiaoService;

    @RequestMapping(value = "/manageHexiaoOrder", method = RequestMethod.GET)
    public String manageHexiaoOrder() {
        return "/order/manageHexiaoOrder";
    }

    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult list(@RequestParam(required = false) Long storeId,
                             @RequestParam(required = false) Integer hexiaoType,
                             @RequestParam(required = false) String startDate,
                             @RequestParam(required = false) String endDate,
                             @RequestParam(defaultValue = "0") int pageIndex, @RequestParam(defaultValue = "10") int pageSize){
        try {
            List<QsgHexiao> orders = hexiaoService.getHexiaoOrderByPage(storeId,hexiaoType,startDate,endDate,pageIndex, pageSize);
            int total = hexiaoService.getTotal(storeId,hexiaoType,startDate,endDate);
            return CommonResult.createSuccessResult(orders, total, "查询核销信息成功.");
        } catch (BusinessException be) {
            logger.error("发生业务异常,异常信息:{}", be.getMessage());
            return CommonResult.createFailureResult("查询核销信息失败.");
        } catch (Exception e) {
            logger.error("发生系统异常,异常信息:{}", e.getMessage());
            return CommonResult.createFailureResult("查询核销信息失败.");
        }
    }

//    @ResponseBody
//    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
//    public CommonResult delete(@PathVariable Integer id) {
//        logger.info("准备删除店铺信息ID:{}", id);
//        try {
//            storeService.removeQsgStoreById(id);
//            return CommonResult.createSuccessResult("删除店铺信息成功.");
//        } catch (BusinessException be) {
//            logger.error("发生业务异常,异常信息:{}", be.getMessage());
//            return CommonResult.createFailureResult("删除店铺信息失败.");
//        } catch (Exception e) {
//            logger.error("发生系统异常,异常信息:{}", e.getMessage());
//            return CommonResult.createFailureResult("删除店铺信息失败.");
//        }
//    }

}
